﻿using System;
using System.Web;

using System.Text;
using System.Data;
using System.Xml;
using System.Web.SessionState;
using System.Web.Services;
using Gift.Model;
using Gift.WebApp;
using Gift.DAL;
using System.Collections;

namespace WebApp.cn.ashx
{
    public class freightWayHandler : IHttpHandler, IRequiresSessionState
    {

        readonly BasePage thePage = new BasePage();

        /// <summary>
        /// 您将需要在您网站的 web.config 文件中配置此处理程序，
        /// 并向 IIS 注册此处理程序，然后才能进行使用。有关详细信息，
        /// 请参见下面的链接: http://go.microsoft.com/?linkid=8101007
        /// </summary>
        #region IHttpHandler Members

       
        DALCard theCard;

        public bool IsReusable
        {
            // 如果无法为其他请求重用托管处理程序，则返回 false。
            // 如果按请求保留某些状态信息，则通常这将为 false。
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            if ((HttpContext.Current.Request.Form["fid"] != null) && (HttpContext.Current.Request.Form["rn"] != null))
            {
                object obj2;
                string s = "";
                DataTable freightWayByFreightTemplate = BaseFactory.theFreightWay.GetFreightWayByFreightTemplate(Convert.ToInt32(HttpContext.Current.Request.Form["fid"]));
                ArrayList list = new ArrayList();
                foreach (DataRow row in freightWayByFreightTemplate.Rows)
                {
                    if (!(list.Contains(Convert.ToInt32(row["deliveryWayId"])) || !row["region"].ToString().Contains(HttpContext.Current.Request.Form["rn"])))
                    {
                        obj2 = s;
                        s = string.Concat(new object[] { obj2, "<span>", row["deliveryWay"], ":", Convert.ToDecimal(row["defaultFreight"]).ToString("0.0"), "Ԫ</span>" });
                        list.Add(Convert.ToInt32(row["deliveryWayId"]));
                    }
                }
                foreach (DataRow row in freightWayByFreightTemplate.Rows)
                {
                    if ((!list.Contains(Convert.ToInt32(row["deliveryWayId"])) && !row["region"].ToString().Contains(HttpContext.Current.Request.Form["rn"])) && (row["region"].ToString() == "0"))
                    {
                        obj2 = s;
                        s = string.Concat(new object[] { obj2, "<span>", row["deliveryWay"], ":", Convert.ToDecimal(row["defaultFreight"]).ToString("0.0"), "Ԫ</span>" });
                        list.Add(Convert.ToInt32(row["deliveryWayId"]));
                    }
                }
                HttpContext.Current.Response.Write(s);
            }
        }

        #endregion
    }
}
